package com.zygh.policeasset.controller;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.ConstructionChange;
import com.zygh.policeasset.service.ConstructionChangeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = {"施工变更管理"})
@RequestMapping({"constructionChange"})
@RestController
public class ConstructionChangeController {
    @Resource
    ConstructionChangeService constructionChangeService;

    @GetMapping({"selectOne"})
    @ApiOperation("通过ID查询")
    public ConstructionChange selectOne(Integer id) {
        return this.constructionChangeService.queryById(id);
    }

    @GetMapping({"queryAll"})
    @ApiOperation("分页查询全部")
    public PageInfo queryAll(@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum, @RequestParam(defaultValue = "10", value = "pageSize") Integer pageSize, @RequestParam(value = "status", required = false) Integer status, @RequestParam(value = "handWay", required = false) Integer handWay, @RequestParam(value = "unit", required = false) String unit, @RequestHeader(value = "findAll", required = false) boolean findAll, @RequestHeader(value = "userId", required = false) Integer userId, @RequestParam(value = "rehabilitation", required = false) Integer rehabilitation) {
        if (findAll) {
            return this.constructionChangeService.queryAll(pageNum.intValue(), pageSize.intValue(), null, status, handWay, unit, rehabilitation);
        }
        return this.constructionChangeService.queryAll(pageNum.intValue(), pageSize.intValue(), userId, status, handWay, unit, rehabilitation);
    }

    @GetMapping({"queryStatistical"})
    @ApiOperation("分页统计")
    public PageInfo queryStatistical(@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum, @RequestParam(defaultValue = "10", value = "pageSize") Integer pageSize, @RequestParam(value = "status", required = false) Integer status, @RequestParam(value = "handWay", required = false) Integer handWay, @RequestParam(value = "unit", required = false) String unit, @RequestHeader(value = "findAll", required = false) boolean findAll, @RequestHeader(value = "userId", required = false) Integer userId) {
        if (findAll) {
            return this.constructionChangeService.queryStatistical(pageNum.intValue(), pageSize.intValue(), null, status, handWay, unit);
        }
        return this.constructionChangeService.queryStatistical(pageNum.intValue(), pageSize.intValue(), userId, status, handWay, unit);
    }

    @PostMapping({"insert"})
    @ApiOperation("添加")
    public CommonResult insert(@RequestBody ConstructionChange constructionChange) {
        return this.constructionChangeService.insert(constructionChange);
    }

    @PostMapping({"update"})
    @ApiOperation("修改")
    public CommonResult update(@RequestBody ConstructionChange constructionChange) {
        return this.constructionChangeService.update(constructionChange);
    }

    @DeleteMapping({"/delete/{id}"})
    @ApiOperation("根据id删除")
    public CommonResult delete(@PathVariable Integer id) {
        return this.constructionChangeService.deleteById(id);
    }

    @PostMapping({"/rehabilitation"})
    @ApiOperation("复建")
    public CommonResult rehabilitation(@RequestBody JSONObject json) {
        return this.constructionChangeService.rehabilitation(json.getInteger("id"));
    }
}